package com.tjetc.service.impl;

import com.tjetc.entity.User;
import com.tjetc.mapper.UserMapper;
import com.tjetc.service.IUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tjetc.utils.MinioUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;


@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {

    @Resource
    private UserMapper userMapper;

    @Autowired
    private MinioUtils minioUtils;

    @Override
    public Integer getMaxId() {
        return userMapper.getMaxId();
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean updates(User user, MultipartFile photo, String[] paths) {
        if (photo!=null){
            String path = minioUtils.upload(photo);
            user.setPhotopath(path);
        }
        userMapper.updateById(user);
        return true;
    }


}
